package com.xyzh05.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="transaction_entry")
@Searchable
@XmlRootElement
public class TransactionEntry extends BaseObject implements Serializable {
	private static final long serialVersionUID = 7416640109549582238L;
	
	private Long id;
    private Date startTime;
    private Date finishTime;
    private Long schoolNum;
    private Double payment;
    private User user;
    private Editor editor;
    private Service service;
    private Long transactionId;
    private Long step;
    private Date deadline;
    private Boolean finished;
    private Boolean clientupdated;
    private Boolean editorupdated;
    private Transaction transaction;
    private List<VipServiceTransaction> vipServiceTransaction;
    
    @OneToMany( mappedBy = "transactionEntry", fetch = FetchType.LAZY) 
    public List<VipServiceTransaction> getVipServiceTransaction() {
		return vipServiceTransaction;
	}

	public void setVipServiceTransaction(
			List<VipServiceTransaction> vipServiceTransaction) {
		this.vipServiceTransaction = vipServiceTransaction;
	}
    
    @ManyToOne(fetch=FetchType.EAGER, cascade = {CascadeType.ALL} )
	@JoinColumn(name="transactionid")
    public Transaction getTransaction() {
		return transaction;
	}

	public void setTransaction(Transaction transaction) {
		this.transaction = transaction;
	}

	@Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="startTime", nullable=false, length=19)
    @SearchableProperty
    public Date getStartTime() {
        return this.startTime;
    }
    
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="finishTime", length=19)
    @SearchableProperty
    public Date getFinishTime() {
        return this.finishTime;
    }
    
    public void setFinishTime(Date finishTime) {
        this.finishTime = finishTime;
    }
    
    @Column(name="schoolNum")
    @SearchableProperty
    public Long getSchoolNum() {
        return this.schoolNum;
    }
    
    public void setSchoolNum(Long schoolNum) {
        this.schoolNum = schoolNum;
    }
    
    @Column(name="payment", nullable=false, precision=22, scale=0)
    @SearchableProperty
    public Double getPayment() {
        return this.payment;
    }
    
    public void setPayment(Double payment) {
        this.payment = payment;
    }
    
    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="clientid", nullable=false)
    public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="editorid", nullable=false, referencedColumnName="userid")
    public Editor getEditor() {
		return editor;
	}

	public void setEditor(Editor editor) {
		this.editor = editor;
	}

	
	@OneToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="serviceid", nullable=false)
    public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

    
    @Column(name="step")
    @SearchableProperty
    public Long getStep() {
        return this.step;
    }
    
    public void setStep(Long step) {
        this.step = step;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="deadline", nullable=false, length=19)
    @SearchableProperty
    public Date getDeadline() {
        return this.deadline;
    }
    
    public void setDeadline(Date deadline) {
        this.deadline = deadline;
    }
    
    @Column(name="finished")
    @SearchableProperty
    public Boolean getFinished() {
        return this.finished;
    }
    
    public void setFinished(Boolean finished) {
        this.finished = finished;
    }
    
    @Column(name="clientupdated")
    @SearchableProperty
    public Boolean getClientupdated() {
        return this.clientupdated;
    }
    
    public void setClientupdated(Boolean clientupdated) {
        this.clientupdated = clientupdated;
    }
    
    @Column(name="editorupdated")
    @SearchableProperty
    public Boolean getEditorupdated() {
        return this.editorupdated;
    }
    
    public void setEditorupdated(Boolean editorupdated) {
        this.editorupdated = editorupdated;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TransactionEntry pojo = (TransactionEntry) o;

        if (startTime != null ? !startTime.equals(pojo.startTime) : pojo.startTime != null) return false;
        if (finishTime != null ? !finishTime.equals(pojo.finishTime) : pojo.finishTime != null) return false;
        if (schoolNum != null ? !schoolNum.equals(pojo.schoolNum) : pojo.schoolNum != null) return false;
        if (payment != null ? !payment.equals(pojo.payment) : pojo.payment != null) return false;
        if (user != null ? !user.equals(pojo.user) : pojo.user != null) return false;
        if (editor != null ? !editor.equals(pojo.editor) : pojo.editor != null) return false;
        if (service != null ? !service.equals(pojo.service) : pojo.service != null) return false;
        if (transactionId != null ? !transactionId.equals(pojo.transactionId) : pojo.transactionId != null) return false;
        if (step != null ? !step.equals(pojo.step) : pojo.step != null) return false;
        if (deadline != null ? !deadline.equals(pojo.deadline) : pojo.deadline != null) return false;
        if (finished != null ? !finished.equals(pojo.finished) : pojo.finished != null) return false;
        if (clientupdated != null ? !clientupdated.equals(pojo.clientupdated) : pojo.clientupdated != null) return false;
        if (editorupdated != null ? !editorupdated.equals(pojo.editorupdated) : pojo.editorupdated != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (startTime != null ? startTime.hashCode() : 0);
        result = 31 * result + (finishTime != null ? finishTime.hashCode() : 0);
        result = 31 * result + (schoolNum != null ? schoolNum.hashCode() : 0);
        result = 31 * result + (payment != null ? payment.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        result = 31 * result + (editor != null ? editor.hashCode() : 0);
        result = 31 * result + (service != null ? service.hashCode() : 0);
        result = 31 * result + (transactionId != null ? transactionId.hashCode() : 0);
        result = 31 * result + (step != null ? step.hashCode() : 0);
        result = 31 * result + (deadline != null ? deadline.hashCode() : 0);
        result = 31 * result + (finished != null ? finished.hashCode() : 0);
        result = 31 * result + (clientupdated != null ? clientupdated.hashCode() : 0);
        result = 31 * result + (editorupdated != null ? editorupdated.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("startTime").append("='").append(getStartTime()).append("', ");
        sb.append("finishTime").append("='").append(getFinishTime()).append("', ");
        sb.append("schoolNum").append("='").append(getSchoolNum()).append("', ");
        sb.append("payment").append("='").append(getPayment()).append("', ");
        sb.append("clientId").append("='").append(getUser()).append("', ");
        sb.append("editorId").append("='").append(getEditor()).append("', ");
        sb.append("serviceId").append("='").append(getService()).append("', ");
        sb.append("transactionId").append("='").append(getTransaction()).append("', ");
        sb.append("step").append("='").append(getStep()).append("', ");
        sb.append("deadline").append("='").append(getDeadline()).append("', ");
        sb.append("finished").append("='").append(getFinished()).append("', ");
        sb.append("clientupdated").append("='").append(getClientupdated()).append("', ");
        sb.append("editorupdated").append("='").append(getEditorupdated()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
